import pymysql
try:
    conn = pymysql.connect(host="127.0.0.1",
                           port=3306,
                           user="root",
                           password="root",
                           database="books",
                           charset="utf8")
    cursor = conn.cursor()
    sql = "insert into t_book(id,title,`read`,comment,pub_date)values(16,'python从入门到精通',50,0,'2020-01-01')"
    cursor.execute(sql)
    print(cursor.rowcount)
    sql="update t_book set comment = 250 where title like 'python%'"
    cursor.execute(sql)
    print(cursor.rowcount)
    sql="delete from t_book where title like 'python%'"
    cursor.execute(sql)
    print(cursor.rowcount)
    sql="select title from t_book "
    cursor.execute(sql)
    print(cursor.fetchall())
    conn.commit()
except Exception as f:
    print(f)
    conn.rollback()
finally:
    cursor.close()
    conn.close()